﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Station.Inspect.Forms
{
    public partial class FormSketch : Form
    {
        public FormSketch()
        {
            InitializeComponent();
            FormClosed += FormSketch_FormClosed;
        }

        private void FormSketch_FormClosed(object sender, FormClosedEventArgs e)
        {
            FormDics.RemoveForm(this);
        }

        private void FormSketch_Load(object sender, EventArgs e)
        {
            UpdateData(false);
        }

        private void btnSetOrig_Click(object sender, EventArgs e)
        {
            //StaInspect.Instance.Prj.sketchOrig = StaInspect.Instance.GetCurPos();
            //StaInspect.Instance.Rbt.Orig = StaInspect.Instance.Prj.sketchOrig;
            StaInspect.Instance.UpdateOrg(StaInspect.Instance.GetCurPos());
            UpdateData(false);
        }

        private void btnSetSize_Click(object sender, EventArgs e)
        {
            var end = StaInspect.Instance.GetCurPos();
            var size = StaInspect.Instance.Prj.sketchOrig-end;
            StaInspect.Instance.Prj.sketchSize = size;
            UpdateData(false);
        }

        private void btnScan_Click(object sender, EventArgs e)
        {
            StaInspect.Instance.Prj.sketchProp = double.Parse(tbProp.Text) / 100;

            if(StaInspect.Instance.IsBusy()==false)
            {
                StaInspect.Instance.StartMakeSketch();
            }
        }

        void UpdateData(bool control2Value=true)
        {
            if(control2Value)
            {

            }
            else
            {
                Project prj = StaInspect.Instance.Prj;
                tbOrig.Text = prj.sketchOrig.ToString();
                tbSize.Text = prj.sketchSize.ToString();
                tbProp.Text = (prj.sketchProp * 100).ToString();
            }
        }
    }
}
